//
//  UseZStack.swift
//  learn-ios
//
//  Created by Dong on 2022/4/5.
//

import SwiftUI

import UIKit

struct UseZStack: View {
    let colors: [Color] = [.blue,.yellow,.brown,.gray,.red]
    var body: some View {
        VStack {
            ZStack {
                Color.blue.frame(width: 300, height: 300, alignment: .top)
                Circle()
                    .frame(width: 100, height: 100, alignment: .top)
            }
            
            ZStack {
                ForEach(0..<colors.count,id:\.self) {
                    Rectangle()
                        // 颜色填充
                        .fill(colors[$0])
                        .frame(width: 100, height: 100, alignment: .top)
                        // 偏移(x:10,y:10)
                        .offset(x: CGFloat($0) * 10, y: CGFloat($0) * 10)
                }
            }
        }
        
    }
}

struct UseZStack_Previews: PreviewProvider {
    static var previews: some View {
        UseZStack()
    }
}
